package com.bigtotoro.shuiyincamera;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.bigtotoro.shuiyincamera.R;
import com.bigtotoro.shuiyincamera.model.BaseResponse;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.umeng.analytics.MobclickAgent;

import qiu.niorgai.StatusBarCompat;

/**
 * 用户反馈
 * */
public class FeedbackActivity extends BaseActivity implements View.OnClickListener {
    private EditText edit_content;
    private TextView btnSubmit;
    private int mode = 1;
    private TextView title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_feedback);
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.theme_color));
        initBase();
        initView();

    }

    private void initView() {
        edit_content = findViewById(R.id.edit_content);
        findViewById(R.id.btn_submit).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_submit:
//                Toast.makeText(this, "反馈已提交", Toast.LENGTH_SHORT).show();
                saveFeedback();
                break;
        }
    }

    private void saveFeedback() {
        String content = edit_content.getText().toString().trim();
        if (content.length() == 0){
            Toast.makeText(this, R.string.warning10, Toast.LENGTH_SHORT).show();
            return;
        }
        OkGo.<String>post(Constant.API + "app/post_feedback").tag(this)
                .headers("Content-Type", "application/x-www-form-urlencoded")
                .params("app","dakacamera")
                .params("content",content)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        BaseResponse base = new Gson().fromJson(response.body(), BaseResponse.class);
                        if (base.getCode() == 0) {
//                            Toast.makeText(FeedbackActivity.this, "" + base.getMsg(), Toast.LENGTH_SHORT).show();
                            finish();
                        } else {
                            Toast.makeText(FeedbackActivity.this, "" + base.getMsg(), Toast.LENGTH_SHORT).show();
                        }
                    }
                    @Override
                    public void onError(Response<String> response) {
                        Toast.makeText(FeedbackActivity.this, R.string.error_500, Toast.LENGTH_SHORT).show();
                    }
                });
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("FeedbackActivity");//统计页面
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("FeedbackActivity");//统计页面
        MobclickAgent.onPause(this);
    }
}
